import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { ProductImage } from 'src/types/product_image.interface';

@Injectable()
export class ProductImageService {
    constructor(@InjectModel('ProductImage') private productImageModel: Model<ProductImage>) {

    }
    async findAllActive():Promise<ProductImage[]>{
        return this.productImageModel.find({isActive:true}).exec()
    }
    async create(createProductImageDto:ProductImage|ProductImage[]):Promise<ProductImage|ProductImage[]>{
     if(Array.isArray(createProductImageDto)){
        return await this.productImageModel.insertMany(createProductImageDto)
     }else{
        const newProductImage = new this.productImageModel(createProductImageDto)
        return await newProductImage.save();
     }
    }

}
